import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { MdlSnackbarService, MdlDialogService } from '@angular-mdl/core';
import { TreeNode, DynamicDialogRef, DynamicDialogConfig } from 'primeng/primeng';
@Component({
  templateUrl: './cancel.component.html',
  styleUrls: ['./cancel.component.scss'],
  providers: []
})
export class CancelComponent implements OnInit {
  systemUrl: string;
  selectedRecords: any = {};
  opinion: string = '';
  constructor(
    private http: HttpClient,
    public ref: DynamicDialogRef,
    public config: DynamicDialogConfig,
    public mdlSnackbarService: MdlSnackbarService
  ) {
    this.systemUrl = config.data.systemUrl;
    this.selectedRecords = config.data.selectedRecords;
  }

  ngOnInit() {
  }

  /** 办结 */
  save() {
    this.http.post('/' + this.systemUrl + '/api/workflow/cancel',
      {
        'recId': this.selectedRecords[0]['rec_id'],
        'actId': this.selectedRecords[0]['act_id'] || 0,
        'opinion': this.opinion
      }).subscribe(data => {
        this.ref.close(data);
        this.mdlSnackbarService.showToast('作废操作成功！')
      });
  }

  /** 取消 */
  cancel() {
    this.ref.close();
  }
}